/**
 * 
 */
package it.irondev.appturismo.service.impl;

import it.irondev.appturismo.dao.DifficultyMapper;
import it.irondev.appturismo.dao.HikeMapper;
import it.irondev.appturismo.dao.example.HikeExample;
import it.irondev.appturismo.dao.example.HikeExample.Criteria;
import it.irondev.appturismo.entity.Difficulty;
import it.irondev.appturismo.entity.Hike;
import it.irondev.appturismo.filter.BaseFilter;
import it.irondev.appturismo.service.IHikeService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author federicocerruto
 *
 */
@Service
public class HikeServiceImpl implements IHikeService {

	@Autowired
	private HikeMapper hikeDao;
	
	@Autowired
	private DifficultyMapper diffDao;
	


	public List<Hike> getAllHikes() {
		return hikeDao.selectByExample(null);
	}

	
	public void addHike(Hike hike) {
		hikeDao.insert(hike);
	}

	
	public void updateHike(Hike hike) {
		hikeDao.updateByPrimaryKeySelective(hike);
	}

	
	public void deleteHike(Integer idHike) {
		hikeDao.deleteByPrimaryKey(idHike);
	}


	public List<Difficulty> getAllDifficulties() {
		return diffDao.selectByExample(null);
	}

	public List<Hike> getHikeByFilter(BaseFilter filter) {
		HikeExample example = null;
		if(filter!=null) {
			example = new HikeExample();
			Criteria criteria = example.createCriteria();
			if(filter.getId()!=null)
				criteria.andIdhikeEqualTo(filter.getId());
			if(filter.getIdlanguage()!=null)
				criteria.andLanguageEqualTo(filter.getIdlanguage());
			example.or(criteria);
		}
			
		return hikeDao.selectByExample(example);
	}

}
